package com.yc.meeting_attendance.utils;

import android.content.Context;
import android.content.SharedPreferences;

import com.yc.meeting_attendance.net.Api;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2016-04-27.
 */
public class SharePreferenceUtil {
    private SharedPreferences sp;
    private SharedPreferences.Editor editor;

    public SharePreferenceUtil(Context context, String file) {
        sp = context.getSharedPreferences(file, context.MODE_PRIVATE);
        editor = sp.edit();
    }



    //教室编号
    public void setClassId(String id) {
        editor.putString("classId", id);
        editor.commit();
    }

    public String getClassId() {
        return sp.getString("classId", "0");
    }
    //服务器地址
    public void setServerAddress(String address){
        editor.putString("serverAddress",address);
        editor.commit();
    }
    public String getServerAddress(){
        return sp.getString("serverAddress", Api.BASE_URL);
    }


    //up服务器地址
    public void setCampusServerAddress(String address){
        editor.putString("campusServerAddress",address);
        editor.commit();
    }

    public String getCampusServerAddress(){
        return sp.getString("campusServerAddress", Api.BASE_URL);
    }
    public void setCom(int com){
        editor.putInt("Com",com);
        editor.commit();
    }

    public int getCom(){
        return sp.getInt("Com",3);
    }

    public void setEquipment(String equipment){
        editor.putString("equipment",equipment);
        editor.commit();
    }

    public String getEquipment(){
        return sp.getString("equipment","000023");
    }
    public void setPass(String pass){
        editor.putString("pass",pass);
        editor.commit();
    }

    public String getPass(){
        return sp.getString("pass","666666");
    }
    // 密钥
    public  void setCardKey(String value) {
        editor.putString("key",value);
        editor.commit();
    }

    public  String getCarKey() {
        return sp.getString("key","0");
    }
    //扇区
    public  void setCardSection(int section) {
        editor.putInt("section",section);
        editor.commit();

    }

    public  int getCarSection() {
        return sp.getInt("section",1);
    }


    //签到提前多少分钟
    public  void setAdvance(int Advance) {
        editor.putInt("Advance",Advance);
        editor.commit();

    }

    public  int getAdvance() {
        return sp.getInt("Advance",1);
    }
    //迟到分钟
    public  void setBeLatee(int BeLate) {
        editor.putInt("BeLate",BeLate);
        editor.commit();

    }

    public  int getBeLate() {
        return sp.getInt("BeLate",1);
    }

    //缺勤分钟
    public  void setAbsenteeisn(int Absenteeisn) {
        editor.putInt("Absenteeisn",Absenteeisn);
        editor.commit();

    }

    public  int geAbsenteeisn() {
        return sp.getInt("Absenteeisn",1);
    }

    //0：不开启签退，1：开启签到
    public  void setNeedCheckout(int NeedCheckout) {
        editor.putInt("NeedCheckout",NeedCheckout);
        editor.commit();

    }

    public  int getNeedCheckout() {
        return sp.getInt("NeedCheckout",0);
    }
    //签退提前分钟
    public  void setoutBefore(int outBefore) {
        editor.putInt("outBefore",outBefore);
        editor.commit();

    }

    public  int getoutBefore() {
        return sp.getInt("outBefore",1);
    }
    //早退分钟
    public  void setleaveEalryint(int leaveEalry) {
        editor.putInt("leaveEalry",leaveEalry);
        editor.commit();

    }

    public  int getleaveEalry() {
        return sp.getInt("leaveEalry",1);
    }

    //签退延迟分钟
    public  void setOutLate(int OutLate) {
        editor.putInt("OutLate",OutLate);
        editor.commit();

    }

    public  int getOutLate() {
        return sp.getInt("OutLate",1);
    }
    //是否加载进数据库数据
    public  void setFig(boolean Fig) {
        editor.putBoolean("Fig",Fig);
        editor.commit();

    }

    public  boolean getFig() {
        return sp.getBoolean("Fig",false);
    }



    public  void setDataFig(boolean Subscript) {
        editor.putBoolean("data",Subscript);
        editor.commit();

    }

    public  boolean getDataFig() {
        return sp.getBoolean("data",false);
    }
    public  void setIndexEnd(int index) {
        editor.putInt("indexEnd",index);
        editor.commit();

    }
    public  int getIndexEnd() {
        return sp.getInt("indexEnd",0);
    }

    public  void setIndexBigen(int index) {
        editor.putInt("indexBigen",index);
        editor.commit();

    }
    public  int getIndexBigen() {
        return sp.getInt("indexBigen",0);
    }
    public  int getRealized() {
        return sp.getInt("realized",0);
    }

    public  void setRealized(int realized) {
        editor.putInt("realized",realized);
        editor.commit();

    }


    public  void setSubscript(boolean Subscript) {
        editor.putBoolean("Subscript",Subscript);
        editor.commit();

    }

    public  boolean getSubscript() {
        return sp.getBoolean("Subscript",false);
    }
    //保存房间UUID
    public List<String>  getMeetingId(){
        List<String>list = new ArrayList<>();
        int size = sp.getInt("meetingId",1);
        for(int i=0;i<size;i++) {
            list.add(sp.getString("meetingId_" + i, null));
        }

        return list;
    }
    public  void  setMeetingId(List<String> list){
        editor.putInt("meetingId",list.size());
        for(int i=0;i<list.size();i++) {
            editor.remove("meetingId_" + i);
            editor.putString("meetingId_" + i, list.get(i));
        }

        editor.commit();
    }
    //保存结束
    public List<String>  getEndCard(){
        List<String>list = new ArrayList<>();
        int size = sp.getInt("endCard",1);
        for(int i=0;i<size;i++) {
            list.add(sp.getString("endCard_" + i, null));
        }

        return list;
    }
    public  void  settEndCard(List<String> list){
        editor.putInt("endCard",list.size());
        for(int i=0;i<list.size();i++) {
            editor.remove("endCard_" + i);
            editor.putString("endCard_" + i, list.get(i));
        }

        editor.commit();
    }
    //保存开始时间
    public List<String>  getBigenCard(){
        List<String>list = new ArrayList<>();
        int size = sp.getInt("bigenCard",1);
        for(int i=0;i<size;i++) {
            list.add(sp.getString("bigenCard_" + i, null));
        }

        return list;
    }
    public  void  setbigenCard(List<String> list){
        editor.putInt("bigenCard",list.size());
        for(int i=0;i<list.size();i++) {
            editor.remove("bigenCard_" + i);
            editor.putString("bigenCard_" + i, list.get(i));
        }

        editor.commit();
    }
    // 重启标记
    public  void setRestartFlag(String value) {
        editor.putString("RestartFlag",value);
        editor.commit();
    }

    public  String getRestartFlag() {
        return sp.getString("RestartFlag","");
    }

    //isFlagTui
    public  void setIsFlagTui(boolean isFlagTui) {
        editor.putBoolean("isFlagTui",isFlagTui);
        editor.commit();

    }

    public  boolean getIsFlagTui() {
        return sp.getBoolean("isFlagTui",false);
    }
   //是否手动上传
    public  void setIsManualUpload(boolean Subscript) {
        editor.putBoolean("ManualUpload",Subscript);
        editor.commit();

    }

    public  boolean getIsManualUpload() {
        return sp.getBoolean("ManualUpload",false);
    }
    public void setUPAddress(String address) {
        editor.putString("UPAddress", address);
        editor.commit();
    }
    public String getUPAddress() {
        return sp.getString("UPAddress","http://10.10.8.46:8000");
    }
}
